package cn.enjoy.sharding.config;

import cn.enjoy.tool.utils.SnowflakeUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;

import java.util.Properties;

/**
 * @author K
 * @date 2023-10-30 17:48
 */
@Slf4j
public class EnjoySnowflakeKeyAlgorithm implements KeyGenerateAlgorithm {
    @Getter
    @Setter
    private Properties props = new Properties();

    /**
     * Get type.
     *
     * @return type
     */
    @Override
    public String getType() {
        return "ENJOY_SNOWFLAKE";
    }

    /**
     * Generate key.
     *
     * @return generated key
     */
    @Override
    public Comparable<?> generateKey() {
        return SnowflakeUtil.getId();
    }

    @Override
    public void init() {

    }
}
